import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';

import {
  BaseResponse,
  TimestampsWrapper,
  PageResponse,
} from '@server/basic-dto';

export class CreateOrUpdateDictionaryTypeDto {
  @ApiProperty({
    description: '字典类型编码',
    type: String,
  })
  code: string;

  @ApiProperty({
    description: '字典类型名称',
    type: String,
  })
  name: string;
}

export class CreateOrUpdateDictionaryDto {
  @ApiProperty({
    description: '字典类型id',
    type: String,
  })
  type: string;

  @ApiProperty({
    description: '字典名称',
    type: String,
  })
  name: string;

  @ApiProperty({
    description: '字典值',
    type: String,
  })
  value: string;

  @ApiProperty({
    description: '语言',
    type: String,
    required: false,
  })
  locale: string;
}

export class DictionaryTypeItem extends TimestampsWrapper {
  @ApiProperty({
    description: '字典类型编码',
    type: String,
  })
  code: string;

  @ApiProperty({
    description: '字典类型名称',
    type: String,
  })
  name: string;
}

export class AllDictionaryTypeResponse extends BaseResponse {
  @ApiProperty({
    description: '字典类型信息',
    type: DictionaryTypeItem,
    isArray: true,
  })
  @Type(() => DictionaryTypeItem)
  data: Array<DictionaryTypeItem>;
}

export class DictionaryItem extends TimestampsWrapper {
  @ApiProperty({
    description: '字典名称',
    type: String,
  })
  name: string;

  @ApiProperty({
    description: '字典值',
    type: String,
  })
  value: string;

  @ApiProperty({
    description: '字典类型信息',
    type: CreateOrUpdateDictionaryTypeDto,
  })
  @Type(() => CreateOrUpdateDictionaryTypeDto)
  type: CreateOrUpdateDictionaryTypeDto;
}

export class QueryDictionariesData extends PageResponse {
  @ApiProperty({
    description: '字典列表',
    type: DictionaryItem,
    isArray: true,
  })
  @Type(() => DictionaryItem)
  list: Array<DictionaryItem>;
}

export class QueryDictionariesListResponse extends BaseResponse {
  @ApiProperty({
    description: '列表分页信息',
    type: QueryDictionariesData,
  })
  @Type(() => QueryDictionariesData)
  data?: QueryDictionariesData;
}

export class QueryDictionariesByTypeResponse extends BaseResponse {
  @ApiProperty({
    description: '字典信息',
    type: DictionaryItem,
    isArray: true,
  })
  @Type(() => DictionaryItem)
  data: Array<DictionaryItem>;
}
